package com.xishu.dao.jpa;

import com.xishu.entity.shop.DiscountTicket;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.persistence.Tuple;
import javax.transaction.Transactional;
import java.util.List;

public interface DiscountTicketDao extends JpaRepository<DiscountTicket, Long>, JpaSpecificationExecutor<DiscountTicket> {
    /**
     * 带优惠卷id查
     *
     * @param idTypeList
     * @return
     */
    @Query(value = "select name as y " +
            "from discount_ticket m " +
            "where id in (:idTypeList) group by name", nativeQuery = true)
    public List<Tuple> idTicketReport(List<Long> idTypeList);

    /**
     * 不带优惠卷id查
     *
     * @param companyId
     * @return
     */
    @Query(value = "select name as y " +
            "from discount_ticket m " +
            "where id =:companyId group by name", nativeQuery = true)
    List<Tuple> TicketReport(Long companyId);


    /**
     * 查出过期优惠券
     *
     * @param endExpiredTime
     */
    @Query(value = "select * from discount_ticket m where m.expired = false " +
            "and m.online_ticket = true " +
            "and m.template = true " +
            "and m.end_time is not null " +
            "and m.end_time <= :endExpiredTime ", nativeQuery = true)
    public List<DiscountTicket> expireTicket(Long endExpiredTime);
}
